<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>将数组中的元素依次添加至下拉列表框的项中</title>
<script>
  var arr = [ "北京", "上海", "杭州", "成都", "重庆", "天津", "呼和浩特", "长沙", "南昌" ];
  var s;
  function init() {
    s = document.getElementById("select1");
    for (var i = 0; i < arr.length; i++) {
      var o = document.createElement("option");
      o.innerText = arr[i];
      s.appendChild(o);
    }
  }
  function cre() {
    var e = prompt("输入在下拉列表框中预添加的项", "");
    if (e !== null && e !== "") {
      arr.push(e);
      var o = document.createElement("option");
      o.innerText = e;
      s.appendChild(o);
    }
  }
  function remove() {
    if (arr.length > 0) {
      // 移除下拉列表框的末尾项
      s.removeChild(s.childNodes[arr.length - 1]);
      arr.pop();
    }
  }
</script>
</head>
<body onload="init()">
  <div style="text-align: center">
    <input type="button" value="在下拉列表框中添加一个项" onclick="cre()">
    <input type="button" value="在下拉列表框中删除一个项" onclick="remove()">
    <br>
    <select id="select1" title="Powered by JavaScript array"></select>
  </div>
</body>
</html>